https://blog.nowcoder.net/n/5f6a5c972bf84780b5a8d2bd5a9599dd

struct  Node{

    int cost;
    vector<int> op_idx;

};

//相当于进行深度遍历 找到最长的路径，即为最短时间
int calc(vector<Node> &data, const Node &node) {
    int curr_cost = node.cost;
    int max_cost = 0;
    for (size_t i = 0; i < node.op_idx.size(); i++)
    {
        int next_cost = calc(data, data[node.op_idx[i]]);
        max_cost = max_cost > next_cost ? max_cost : next_cost;
    }    
    return curr_cost + max_cost;
}

int main()
{
   
    int cnt;
   // cin >>cnt;  注意这里不能去代替getline 否则会出问题
    string s_cnt;
    getline(cin, s_cnt);
    cnt = stoi(s_cnt);

    vector<Node> data;
    for (int i = 0; i < cnt;i++) {
        string line;
        string str;
//        while (getline(cin,str)) {
 //           line = line + str;
  //      };
        getline(cin, line);
        regex re(" ");
        vector<string> splited(sregex_token_iterator(line.begin(), line.end(),  re, -1), sregex_token_iterator());
        Node curr;
        curr.cost = stoi(splited[1]);
        for (int i = 2; i < splited.size(); i++) {
            curr.op_idx.push_back( stoi(splited[i]));
        }
        data.emplace_back(curr);
    }
    if (data.size() < 1) return 0;
    int min = calc(data, data[0]);
    return min;

}